The User setup
form allows users to customize their most often used forms to fit their
needs. Users can hide or move form controls, change labels, and so on.
The setup is available for any Dynamics AX form and can be opened from
the right-click context menu by selecting the Setup option.
As a developer, I also use this form very often. For example, it contains the very handy System name field, which displays the name of the currently selected table field or method, so you do not need to search in AOT. The Information
tab page provides information about the form itself, the caller object,
and the menu item used, and it allows opening those objects instantly
in AOT view. The last tab page Query shows the tables used in the form's query, which is also very useful to quickly understand the underlying data structure.
In this recipe, we will enhance the User setup form. We will add a new button to the last tab page, which will open the selected table in AOT.
How to do it...
1. Open SysSetupForm form in AOT, and replace the following code in its fillQueryTreeQueryDatasource():
formTreeItem = new FormTreeItem(
nodeText,
imagelist.image(#ImageDataSource),
-1,
null);
with the code:
formTreeItem = new FormTreeItem(
nodeText,
imagelist.image(#ImageDataSource),
-1,
queryBuildDataSource.table());
2. Add a new ButtonGroup to the QueryPage tab page:
Property
|
Value
|
---|
Name
|
ButtonGroup1
|
3. Add a new Button to the created button group:
Property
|
Value
|
---|
Name
|
EditTable
|
Text
|
Edit
|
AutoDeclaration
|
Yes
|
4. Override the button's clicked() method:
void clicked()
{
FormTreeItem formTreeItem;
TableId tableId;
TreeNode treeNode;
#AOT
;
formTreeItem = QueryTree.getItem(
QueryTree.getSelection());
tableId = formTreeItem.data();
if (!tableId || !tableid2name(tableId))
{
return;
}
treeNode = infolog.findNode(
#TablesPath +
#AOTDelimiter +
tableid2name(tableId));
if (!treeNode)
{
return;
}
treeNode.AOTnewWindow();
}
5. Override selectionChanged() on the QueryTree control:
public void selectionChanged(
FormTreeItem _oldItem,
FormTreeItem _newItem,
FormTreeSelect _how)
{;
super(_oldItem, _newItem, _how);
EditTable.enabled(
tableid2name(_newItem.data())?true:false);
}
6. To test, open any form, for example, Chart of Account Details from the General ledger, and open User setup by right-clicking anywhere on the form and selecting the Setup option:
7. Go to the Query tab page, and select one of the tables in the query displayed:
8. Click the Edit button to open this table in AOT:
How it works...
First, we modify the creation of the query tree control. Normally, each tree node can hold some data. The tree in the SysSetupForm
form does not have any data associated with nodes, so we have to modify
the code and store the table number in each node representing a table.
Next, we add a new button and override its clicked().
In this method, we get the table number stored in the currently
selected node— this is what we stored earlier— and
search for that table in AOT. We display it in a new AOT window if
found.
Finally, we override selectionChanged() on the QueryTree control to make sure the button's status is updated upon node selection. In other words, the Edit button is enabled if the current tree node contains some data, otherwise it is disabled.
In this way, we have modified the User setup form to provide us with a quick AOT access to the underlying tables.